

def test1():
    list1 = ["a.b", "b.b", "c.b"]
    def get_a(s):
        a, _ = s.split('.')
        return a

    list2 = [get_a(s) for s in list1]
    print(list2)
    list3 = {get_a(s): s for s in list1}
    print(list3)


def list_index_test():
    list1 = ["a", "b", "c", "d"]
    print(list1.index("a"))     # ->0
    print(list1.index("c"))     # ->2
    print(len(list1))
    print(list1.index("e"))     # ValueError

    # 接口返回值


def check_list_cross():
    # 判断两个列表的交集
    list1 = ['张三', '李四', '王五', '老二']
    # 数据库返回值
    list2 = ['张三', '李四', '老二', '王七']

    a = [x for x in list1 if x in list2]  # 两个列表中都存在
    b = [y for y in (list1 + list2) if y not in a]  # 两个列表中的不同元素

    print('a的值为:', a)
    print('b的值为:', b)

    c = [x for x in list1 if x not in list2]  # 在list1列表中而不在list2列表中
    d = [y for y in list2 if y not in list1]  # 在list2列表中而不在list1列表中
    print('c的值为:', c)
    print('d的值为:', d)

    s2 = list(set(list1).union(set(list2)))
    print("并集", s2)

if __name__=="__main__":
    #test1()
    #list_index_test()
    check_list_cross()
